package com.unicom.office.func;

import com.unicom.office.runtime.OfficeRuntime;
import com.unicom.office.type.TypeItem;
import com.unicom.office.unit.OfficeUnit;

import java.util.ArrayList;
import java.util.List;

// 例如$r2:for(item in list)代表生成一个forFunc，然后r2代表将两行生成一个BatchFunc赋值给forFunc
public class BatchFunc extends FuncBase{
    private List<FuncBase> funcs;
    private TypeItem typeItem;

    public BatchFunc(TypeItem typeItem) {
        this.typeItem = typeItem;
    }

    public TypeItem getType() {
        return typeItem;
    }

    public BatchFunc(){
        funcs = new ArrayList<FuncBase>();
    }

    public void addFunc(FuncBase funcBase){
        if(funcBase.getType() != typeItem){
            throw new RuntimeException("函数类型不一致");
        }
        funcs.add(funcBase);
    }

    public Object run(OfficeRuntime officeRuntime) {
        // 仅仅是代码集合，不需要参数
        List<Object> objects = new ArrayList<Object>();
        for (FuncBase func : funcs) {
            objects.add(func.run(officeRuntime));
        }
        return objects;
    }

    public void runForMatch(OfficeUnit unit, OfficeRuntime officeRuntime) {

    }
}
